﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
    xmlns:TableDataDictionary="ext:Data"
>
    <xsl:variable name="varStart" select="1"></xsl:variable>
    <xsl:variable name="varEnd" select="TableDataDictionary:GetValue('Count')"></xsl:variable>
    <xsl:variable name="varTotalStart" select="TableDataDictionary:GetValue('TotalStart')"></xsl:variable>
    <xsl:variable name="varTotalEnd" select="TableDataDictionary:GetValue('TotalCount')"></xsl:variable>

    <xsl:template match="/">
        <html>
            <head>
                <title>Products TFS - Daily Tickets Summary</title>
            </head>
            <body>
                <style type="text/css">
                    #ticketstable td{background-color:#FFF;padding:6px;text-align:left;}
                    #ticketstable .nameTD{text-align:left;}
                </style>
                <font face="calibri,arial">
                    <p>
                        Dear <xsl:value-of select="TableDataDictionary:GetValue('DisplayName')"/>,
                    </p>
                    <p>
                        Here is the summary of our team.
                    </p>
                    <table id='ticketstable' cellspacing='1px' cellpadding='6px' border='0px' style='background-color:#ccc;'>
                        <font face="calibri,arial" size="-1">
                            <tr style='font-weight:bold;'>
                                <td>Name</td>
                                <td class='nameTD'>Active</td>
                                <td>Resolved</td>
                            </tr>
                            <xsl:call-template name="for-loop-member">
                                <xsl:with-param name="i" select="$varTotalStart"></xsl:with-param>
                                <xsl:with-param name="count" select="$varTotalEnd"></xsl:with-param>
                            </xsl:call-template>
                        </font>
                    </table>
                    <br/>
                    <br/>
                    
                    <p>
                        <a>
                            <xsl:attribute name="href">
                                <xsl:value-of select="TableDataDictionary:GetValue('MyBugsURL')"/>
                            </xsl:attribute>Here</a> are your currently <xsl:value-of select="TableDataDictionary:GetValue('Count')"/> Active/Resolved assigned tickets.
                    </p>
                    <br/>
                    <div>
                        <table id='ticketstable' cellspacing='1px' cellpadding='6px' border='0px' style='background-color:#ccc;'>
                            <font face="calibri,arial" size="-1">
                                <tr style='font-weight:bold;'>
                                    <td>ID.</td> 
                                    <td class='nameTD'>Title</td>
                                    <td >State</td>
                                    <td >Reason</td>
                                    <td>Changed Date</td>
                                    <td>Changed By</td>
                                </tr>
                                <xsl:call-template name="for-loop">
                                    <xsl:with-param name="i" select="$varStart"></xsl:with-param>
                                    <xsl:with-param name="count" select="$varEnd"></xsl:with-param>
                                </xsl:call-template>
                            </font>
                        </table>
                        <br/>                        
                    </div>
                    <br/><br/>
                    Thank you.<br/>
                </font>
            </body>
        </html>
    </xsl:template>

    <xsl:template name="for-loop">
        <xsl:param name="i"></xsl:param>
        <xsl:param name="count"></xsl:param>

        <xsl:if test="$i &lt;= $count">
            <tr>
                <td>
                    <a>
                        <xsl:attribute name="href">
                            <xsl:value-of select="TableDataDictionary:GetTableDataValue($i, 'Href')"/>
                        </xsl:attribute>
                        <xsl:value-of select="TableDataDictionary:GetTableDataValue($i, 'ID')"/>
                    </a>
                </td> 
                <td class="nameTD">
                    <xsl:value-of select="TableDataDictionary:GetTableDataValue($i, 'Title')"/>
                </td>
                <td>
                    <xsl:value-of select="TableDataDictionary:GetTableDataValue($i, 'State')"/>
                </td>
                <td>
                    <xsl:value-of select="TableDataDictionary:GetTableDataValue($i, 'Reason')"/>
                </td>
                <td>
                    <xsl:value-of select="TableDataDictionary:GetTableDataValue($i, 'ChangedDate')"/>
                </td>
                <td>
                    <xsl:value-of select="TableDataDictionary:GetTableDataValue($i, 'ChangedBy')"/>
                </td>
            </tr>
        </xsl:if>
        <xsl:if test="$i &lt;= $count">
            <xsl:call-template name="for-loop">
                <xsl:with-param name="i" select="$i + 1"></xsl:with-param>
                <xsl:with-param name="count" select="$count"></xsl:with-param>
            </xsl:call-template>
        </xsl:if>
    </xsl:template>


    <xsl:template name="for-loop-member">
        <xsl:param name="i"></xsl:param>
        <xsl:param name="count"></xsl:param>

        <xsl:if test="$i &lt;= $count">
            <tr>
                <td class="nameTD">
                    <xsl:value-of select="TableDataDictionary:GetTableDataValue($i, 'Name')"/>
                </td>
                <td>
                    <xsl:value-of select="TableDataDictionary:GetTableDataValue($i, 'Active')"/>
                </td>
                <td>
                    <xsl:value-of select="TableDataDictionary:GetTableDataValue($i, 'Resolved')"/>
                </td>
            </tr>
        </xsl:if>
        <xsl:if test="$i &lt;= $count">
            <xsl:call-template name="for-loop-member">
                <xsl:with-param name="i" select="$i + 1"></xsl:with-param>
                <xsl:with-param name="count" select="$count"></xsl:with-param>
            </xsl:call-template>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>
